#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int a[N], n, q;

int solve(int x, int y)
{
	int l = 0, r = n;
	while(l < r)
	{
		int mid = (l + r) >> 1;
		if(a[mid] >= x) r = mid;
		else l = mid + 1;
	}
	int lowerbound = l;
	l = 0, r = n;
	while(l < r)
	{
		int mid = (l + r + 1) >> 1;
		if(a[mid] <= y) l = mid;
		else r = mid - 1;
	}
	return max(0, l - lowerbound + 1);
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	cin >> q;
	while(q--)
	{
		int x, y; cin >> x >> y;
		cout << solve(x, y) << endl;
	}
	
	return 0;
}


